/*
 * @lc app=leetcode.cn id=2264 lang=typescript
 *
 * [2264] 字符串中最大的 3 位相同数字
 */

// @lc code=start
function largestGoodInteger(num: string): string {
    let max = "";
    let count = 3;
    let now = "";
    for (let i = 0; i < num.length; i++) {
        const element = num[i];
        if (element === now) {
            count--;
            if (count === 0)
                max = Math.max(parseInt(max || "0"), parseInt(now)).toString();
        } else {
            now = element;
            count = 2;
        }
    }
    return max.repeat(3);
}
// @lc code=end
